﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace ChartEdit
{
    public class KeyValue
    {
        [XmlAttribute]
        public string Key;
        [XmlAttribute]
        public string Value;
    }
    public class SpecialProp
    {
        [XmlAttribute]
        public string Name;

        [XmlAttribute]
        public int Flag;
    }
    public class NoteProp
    {
        [XmlAttribute]
        public int Fret;

        [XmlAttribute]
        public bool IsNote;

        [XmlAttribute]
        public bool FlipsHOPO;
        [XmlAttribute]
        public bool ForcesHOPO;
        [XmlAttribute]
        public bool ForcesStrum;
        [XmlAttribute]
        public int PointValue;
    }
    public class TrackProps
    {
        [XmlAttribute]
        public string Name;

        [XmlAttribute]
        public string HopoLogic;

        public List<NoteProp> NoteProperties;
        public List<SpecialProp> SpecialProperties;

        public TrackProps()
        {
            NoteProperties = new List<NoteProp>();
            SpecialProperties = new List<SpecialProp>();
        }
    }

    public class TrackPropsList : List<TrackProps>
    {
        public TrackProps this[ string key ]
        {
            get
            {
                foreach ( TrackProps tp in this )
                {
                    if ( tp.Name.IndexOf( key, StringComparison.OrdinalIgnoreCase ) == 0 && tp.Name.Length == key.Length )
                        return tp;
                }
                return this[ 0 ];
            }
        }
    }

    public class GameProps
    {
        [XmlAttribute]
        public string Name;

        public TrackPropsList TrackProperties;

        public GameProps()
        {
            TrackProperties = new TrackPropsList();
        }
    }
    public class Globals : Serializable<Globals>
    {
        public List<KeyValue> KeyVals;
        public List<GameProps> GameProperties;

        public string ReplaceKey( string key )
        {
            foreach ( KeyValue kv in KeyVals )
            {
                if ( kv.Key == key )
                    return kv.Value;
            }

            return key;
        }

        public Globals()
        {
            KeyVals = new List<KeyValue>();
            GameProperties = new List<GameProps>();
        }

        public static void Initialize()
        {
            if ( Instance != null )
                return;

            Instance = Globals.Load( "config/globals.xml" );
        }

        public static Globals Instance
        {
            get;
            private set;
        }
    }
}
